<template>
  <div class="container contract-review pb">
    <p class="bread">
      <a href="#/personalcenter">个人中心</a> >
      <a href="#/personalcenter/law" class="font-s-18">订单管理</a> >
      <a href="javascript:void(0);" class="font-s-16">法律服务</a>
    </p>
    <div class="bg-c-fff box-border">
      <h3 class="tm-title">法律服务</h3>
      <step :stepData="stepData" :stepNum="stepNum" @stepRouter="stepRouter"></step>
    </div>
    <div class="content">
      <h3 class=" bg-c-fff">请您分阶段就本次服务进行评价，您的评价对我们非常重要，感谢您的配合。</h3>
      <form @submit.prevent="onSubmitClick">
        <div class="box bg-c-fff">
          <h4>1.律师服务</h4>
          <evaluate ref="num1" :disabled="evalua"></evaluate>
          <textarea placeholder="请您留下宝贵意见" v-model="evaluateOne" :disabled="evalua">
          </textarea>
        </div>
        <div class="box bg-c-fff">
          <h4>2.法律监控服务</h4>
          <evaluate ref="num2" :disabled="evalua"></evaluate>
          <textarea placeholder="请您留下宝贵意见" v-model="evaluateTwo" :disabled="evalua">
          </textarea>
        </div>
        <div class="box bg-c-fff">
          <h4>3.整体服务满意程度</h4>
          <evaluate ref="num3" :disabled="evalua">
          </evaluate>
          <ul>
            <li class="dib">
              <input type="checkbox" id="a" value="系统操作繁琐" v-model="checkboxA" class="vm" :disabled="evalua">
              <label for="a">系统操作繁琐</label>
            </li>
            <li class="dib">
              <input type="checkbox" id="b" value="服务人员态度恶劣" v-model="checkboxB" class="vm" :disabled="evalua">
              <label for="b">服务人员态度恶劣</label>
            </li>
            <li class="dib">
              <input type="checkbox" id="c" value="系统使用卡顿严重" v-model="checkboxC" class="vm" :disabled="evalua">
              <label for="c">系统使用卡顿严重</label>
            </li>
            <li class="dib">
              <input type="checkbox" id="d" value="对我无帮助" v-model="checkboxD" class="vm" :disabled="evalua">
              <label for="d">对我无帮助</label>
            </li>
          </ul>
          <textarea placeholder="请您留下宝贵意见" v-model="evaluateThree" :disabled="evalua">
          </textarea>
          <div class="fix btn" v-if="!this.evalua">
            <div class="flo-right">
              <input type="submit" value="提交评价" class="blue-button xl-btn-css tc">
              <input type="button" value="取消" @click="cancel" class="blue-button xl-btn-css tc">
            </div>
          </div>
        </div>
      </form>
    </div>
  </div>
</template>
<script type="text/javascript">
import Step from '../components/Step'
import Evaluate from '../components/Evaluate'
export default {
  components: {
    Step,
    Evaluate
  },
  data() {
    return {
      stepNum: 3,
      stepData: [{
        name: '确认付款'
      }, {
        name: '监控员绘制流程图'
      }, {
        name: '法律服务监控'
      }, {
        name: '服务评价'
      }],
      evaluateOne: '',
      evaluateTwo: '',
      evaluateThree: '',
      checkboxA: '',
      checkboxB: '',
      checkboxC: '',
      checkboxD: '',
      evalua: false,
      status: ''
    }
  },
  mounted() {
    this.$http.get('/legalService/read/detail', {
      params: {
        id: this.$route.query.id
      }
    }).then(data => {
      if (data.data.httpCode === 200) {
        this.status = data.data.data.status
        if (data.data.data.legalEvaluate) {
          this.evalua = true
          this.$refs.num1.index = data.data.data.legalEvaluate.satisfactory.split(',')[0]
          this.$refs.num2.index = data.data.data.legalEvaluate.satisfactory.split(',')[1]
          this.$refs.num3.index = data.data.data.legalEvaluate.satisfactory.split(',')[2]
          this.evaluateOne = data.data.data.legalEvaluate.evaluateContentOne
          this.evaluateTwo = data.data.data.legalEvaluate.evaluateContentTwo
          let contentThree = data.data.data.legalEvaluate.evaluateContentThree
          this.evaluateThree = contentThree.split('~@$')[0]
          this.checkboxA = contentThree.split('~@$')[1].split(',')[0]
          this.checkboxB = contentThree.split('~@$')[1].split(',')[1]
          this.checkboxC = contentThree.split('~@$')[1].split(',')[2]
          this.checkboxD = contentThree.split('~@$')[1].split(',')[3]
        }
      } else {
        console.log(data.data.msg)
        this.$toasted.show(data.data.msg)
      }
    }).catch(err => {
      console.log(err)
    })
  },
  methods: {
    onSubmitClick() {
      if (!this.evaluateOne && this.$refs.num1.index === 1) {
        this.$toasted.show('请写下您对律师服务的意见')
        return
      }
      if (!this.evaluateTwo && this.$refs.num2.index === 1) {
        this.$toasted.show('请写下您对法律监控服务的意见')
        return
      }
      if (!this.evaluateThree && this.$refs.num3.index === 1) {
        this.$toasted.show('请写下您对整体服务的意见')
        return
      }
      this.$http.post('/evaluate/submit', {
        evaluateId: this.$route.query.id,
        satisfactory: this.$refs.num1.index + ',' + this.$refs.num2.index + ',' + this.$refs.num3.index,
        evaluateType: 2,
        evaluateOne: this.evaluateOne,
        evaluateTwo: this.evaluateTwo,
        evaluatethree: this.evaluateThree + '~@$' + this.checkboxA + ',' + this.checkboxB + ',' + this.checkboxC + ',' + this.checkboxD
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$toasted.show('提交成功，感谢您留下宝贵意见')
          this.$router.push('/personalcenter/law')
        } else {
          console.log(data.data.msg)
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
      })
    },
    stepRouter(i, name) {
      if (i === 0 && this.status >= 1) {
        this.$router.push('/law-service-pay?id=' + this.$route.query.id)
      }
      if (i === 1 && this.status >= 2) {
        this.$router.push('/law-service-chart?id=' + this.$route.query.id)
      }
      if (i === 2 && this.status >= 3) {
        this.$router.push('/law-service-monitor?id=' + this.$route.query.id)
      }
      if (i === 3 && this.status >= 4) {
        this.$router.push('/law-service-evalua?id=' + this.$route.query.id)
      }
    },
    cancel() {
      this.$refs.num1.index = 3
      this.$refs.num2.index = 3
      this.$refs.num3.index = 3
      this.evaluateOne = ''
      this.evaluateTwo = ''
      this.evaluateThree = ''
      this.checkboxA = ''
      this.checkboxB = ''
      this.checkboxC = ''
      this.checkboxD = ''
    }
  }
}

</script>
<style type="text/css" scoped>
.box-border {
  border: 1px solid #ddd;
}

.tm-title {
  line-height: 40px;
  padding-left: 35px;
  font-size: 14px;
  color: #282828;
  border-bottom: 1px solid #ddd;
}

.content .box {
  padding: 20px 40px;
  margin-bottom: 15px;
}

.content .box .white-button {
  width: 100px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  margin: 5px 74px 5px 0;
}

.content .box .box-border-top {
  border-top: 1px solid #ddd;
}

.pb {
  padding-bottom: 50px;
}

.content h3 {
  border-bottom: 1px solid #dddddd;
  color: #282828;
  line-height: 40px;
  padding-left: 40px;
  font-size: 14px;
  margin-top: 15px;
}

.content h4 {
  font-weight: bold;
  color: #282828;
  line-height: 40px;
}

.content .box ul li {
  margin: 23px 20px 10px 0;
}

textarea {
  width: 100%;
  height: 120px;
  margin-top: 15px;
  border-color: #ddd;
  padding: 10px 7px;
}

.content .box .btn input {
  margin: 20px 5px 30px 40px;
}

</style>
